﻿<UserControl x:Class="navigation.Contents.StoryBoardItem"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:s="http://schemas.microsoft.com/surface/2008"
             mc:Ignorable="d" 
             x:Name="ScrumBoardItem"
             >
    <UserControl.Resources>
        <DataTemplate x:Key="ListBoxItemTemplete">
            <Canvas x:Name="stackPanel" Height="150" Width="150">
                <Label 
                        Content="{Binding TaskName}" 
                        Foreground="Black"
                        Background="AntiqueWhite"
                        HorizontalAlignment="Center" 
                        VerticalAlignment="Center"
                        FontSize="20"
                        Width="140"
                        Height="140"/>
            </Canvas>
        </DataTemplate>

        <Style x:Key="CursorStyle" TargetType="{x:Type ContentControl}">
            <Setter Property="ContentTemplate" Value="{StaticResource ListBoxItemTemplete}" />
            <Setter Property="BorderThickness" Value="9"/>
            <Setter Property="BorderBrush" Value="{DynamicResource {x:Static s:SurfaceColors.Accent1BrushKey}}"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ContentControl}">
                        <Border 
                            BorderThickness="{TemplateBinding BorderThickness}" 
                            BorderBrush="{TemplateBinding BorderBrush}">
                            <ContentPresenter Margin="0"
                                Content="{TemplateBinding Content}" 
                                ContentTemplate="{TemplateBinding ContentTemplate}">
                            </ContentPresenter>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="Tag" Value="CanDrop">
                    <Setter Property="BorderBrush" Value="{DynamicResource {x:Static s:SurfaceColors.Accent4BrushKey}}" />
                </Trigger>
                <Trigger Property="Tag" Value="CannotDrop">
                    <Setter Property="BorderBrush" Value="{DynamicResource {x:Static s:SurfaceColors.Accent3BrushKey}}" />
                </Trigger>
            </Style.Triggers>
        </Style>

        <Style TargetType="ListBoxItem" x:Key="ContainerStyle">
            <Setter Property="FocusVisualStyle" Value="{x:Null}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBoxItem">
                        <Border Name="Border" Padding="2" SnapsToDevicePixels="true">
                            <ContentPresenter/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsSelected" Value="true">
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    <Grid MinHeight="200">

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200" Name="StoryCardColumn"/>
            <ColumnDefinition Width="*" Name="Column1"/>
            <ColumnDefinition Width="*" Name="Column2"/>
            <ColumnDefinition Width="*" Name="Column3"/>
        </Grid.ColumnDefinitions>
        <Border BorderBrush="{DynamicResource {x:Static s:SurfaceColors.ListBoxItemBackgroundBrushKey}}" BorderThickness="1" Grid.Column="0" Grid.Row="0"/>
        <Border BorderBrush="{DynamicResource {x:Static s:SurfaceColors.ListBoxItemBackgroundBrushKey}}" BorderThickness="1" Grid.Column="1" Grid.Row="0"/>
        <Border BorderBrush="{DynamicResource {x:Static s:SurfaceColors.ListBoxItemBackgroundBrushKey}}" BorderThickness="1" Grid.Column="2" Grid.Row="0"/>
        <Border BorderBrush="{DynamicResource {x:Static s:SurfaceColors.ListBoxItemBackgroundBrushKey}}" BorderThickness="1" Grid.Column="3" Grid.Row="0"/>

        <Grid Grid.Column="0" AllowDrop="False">            
            <Grid Width="160" Height="130" HorizontalAlignment="Center" VerticalAlignment="Center">
                <Rectangle Name="Rect" RadiusY="2.5" RadiusX="2.5" Height="150" Width="180" Margin="-7,0,-9,-12" Fill="{Binding StoryCardColor}"/>

                <RichTextBox Name="TextBox" Margin="8,52,8,0" FontSize="10" Background="{Binding StoryCardColor}" Foreground="White">
                    <FlowDocument>
                        <Paragraph>
                            <Run Text="{Binding StoryContent, Mode=OneWay}"/>
                        </Paragraph>
                    </FlowDocument>
                </RichTextBox>
                <Label Name="StoryLabel" Content="{Binding StoryName}" HorizontalAlignment="Left" Margin="8,8,0,0" VerticalAlignment="Top" Width="148" Height="30" Foreground="White" FontSize="15" FontStyle="Italic" FontFamily="Arial" />
            </Grid>
        </Grid>

        <s:SurfaceListBox Grid.Column="1" x:Name="PlannedListBox" BorderBrush="{DynamicResource {x:Static s:SurfaceColors.ListBoxItemBackgroundBrushKey}}" ItemTemplate="{StaticResource ListBoxItemTemplete}" ItemContainerStyle="{StaticResource ContainerStyle}"
                          AllowDrop="True" ItemsSource="{Binding ElementName=ScrumBoardItem, Path=PlannedItems}" Margin="0,0,0,0" Visibility="Visible"                     
                          PreviewTouchDown="OnDragSourcePreviewTouchDown" 
                          s:SurfaceDragDrop.Drop="PlannedListBox_OnDropTargetDrop"
                          s:SurfaceDragDrop.DragEnter="OnDropTargetDragEnter"
                          s:SurfaceDragDrop.DragLeave="OnDropTargetDragLeave"
                          s:SurfaceDragDrop.DragCanceled="PlannedListBox_DragCanceled"
                          s:SurfaceDragDrop.DragCompleted="PlannedListBox_DragCompleted"
                          >
            <s:SurfaceListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel Orientation="Horizontal" ItemHeight="160" ItemWidth="160" IsItemsHost="True" Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=s:SurfaceListBox, AncestorLevel=1}, Path=ActualWidth}"/>
                </ItemsPanelTemplate>
            </s:SurfaceListBox.ItemsPanel>
        </s:SurfaceListBox>

        <s:LibraryStack Grid.Column="1" x:Name="PlannedStack" BorderBrush="{DynamicResource {x:Static s:SurfaceColors.ListBoxItemBackgroundBrushKey}}" ItemTemplate="{StaticResource ListBoxItemTemplete}"
                          AllowDrop="True" ItemsSource="{Binding ElementName=ScrumBoardItem, Path=PlannedItems}" Visibility="Collapsed" Height="200" Background="Transparent" Margin="0,1,0,1"
                          PreviewTouchDown="OnDragSourcePreviewTouchDown" 
                          s:SurfaceDragDrop.Drop="PlannedListBox_OnDropTargetDrop"
                          s:SurfaceDragDrop.DragEnter="OnDropTargetDragEnter"
                          s:SurfaceDragDrop.DragLeave="OnDropTargetDragLeave"
                          s:SurfaceDragDrop.DragCanceled="PlannedListBox_DragCanceled"
                          s:SurfaceDragDrop.DragCompleted="PlannedListBox_DragCompleted"
                          >
        </s:LibraryStack>

        <s:SurfaceListBox Grid.Column="2" x:Name="InProgressListBox" BorderBrush="{DynamicResource {x:Static s:SurfaceColors.ListBoxItemBackgroundBrushKey}}" ItemTemplate="{StaticResource ListBoxItemTemplete}" ItemContainerStyle="{StaticResource ContainerStyle}"
                          AllowDrop="True" ItemsSource="{Binding ElementName=ScrumBoardItem, Path=InProgressItems}"  Margin="0,0,0,0"
                          PreviewTouchDown="OnDragSourcePreviewTouchDown"                                                  
                          s:SurfaceDragDrop.Drop="InProgressListBox_OnDropTargetDrop"
                          s:SurfaceDragDrop.DragEnter="OnDropTargetDragEnter"
                          s:SurfaceDragDrop.DragLeave="OnDropTargetDragLeave"
                          s:SurfaceDragDrop.DragCanceled="InProgressListBox_DragCanceled"
                          s:SurfaceDragDrop.DragCompleted="InProgressListBox_DragCompleted"
                          >
            <s:SurfaceListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel Orientation="Horizontal" ItemHeight="160" ItemWidth="160" IsItemsHost="True" Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=s:SurfaceListBox, AncestorLevel=1}, Path=ActualWidth}"/>
                </ItemsPanelTemplate>
            </s:SurfaceListBox.ItemsPanel>
        </s:SurfaceListBox>

        <s:LibraryStack Grid.Column="2" x:Name="InProgressStack" BorderBrush="{DynamicResource {x:Static s:SurfaceColors.ListBoxItemBackgroundBrushKey}}" ItemTemplate="{StaticResource ListBoxItemTemplete}" 
                          AllowDrop="True" ItemsSource="{Binding ElementName=ScrumBoardItem, Path=InProgressItems}" Visibility="Collapsed" Height="200" Background="Transparent" Margin="0,1,0,1" 
                          PreviewTouchDown="OnDragSourcePreviewTouchDown"                                                  
                          s:SurfaceDragDrop.Drop="InProgressListBox_OnDropTargetDrop"
                          s:SurfaceDragDrop.DragEnter="OnDropTargetDragEnter"
                          s:SurfaceDragDrop.DragLeave="OnDropTargetDragLeave"
                          s:SurfaceDragDrop.DragCanceled="InProgressListBox_DragCanceled"
                          s:SurfaceDragDrop.DragCompleted="InProgressListBox_DragCompleted"
                          >
        </s:LibraryStack>

        <s:SurfaceListBox Grid.Column="3" x:Name="DoneListBox" BorderBrush="{DynamicResource {x:Static s:SurfaceColors.ListBoxItemBackgroundBrushKey}}" ItemTemplate="{StaticResource ListBoxItemTemplete}" ItemContainerStyle="{StaticResource ContainerStyle}"
                          AllowDrop="True" ItemsSource="{Binding ElementName=ScrumBoardItem, Path=DoneItems}"  Margin="0,0,0,0"
                          PreviewTouchDown="OnDragSourcePreviewTouchDown"                                                  
                          s:SurfaceDragDrop.Drop="DoneListBox_OnDropTargetDrop"
                          s:SurfaceDragDrop.DragEnter="OnDropTargetDragEnter"
                          s:SurfaceDragDrop.DragLeave="OnDropTargetDragLeave"
                          s:SurfaceDragDrop.DragCanceled="DoneListBox_DragCanceled"
                          s:SurfaceDragDrop.DragCompleted="DoneListBox_DragCompleted"
                          >
            <s:SurfaceListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel Orientation="Horizontal" ItemHeight="160" ItemWidth="160" IsItemsHost="True" Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=s:SurfaceListBox, AncestorLevel=1}, Path=ActualWidth}"/>
                </ItemsPanelTemplate>
            </s:SurfaceListBox.ItemsPanel>
        </s:SurfaceListBox>

        <s:LibraryStack Grid.Column="3" x:Name="DoneStack" BorderBrush="{DynamicResource {x:Static s:SurfaceColors.ListBoxItemBackgroundBrushKey}}" ItemTemplate="{StaticResource ListBoxItemTemplete}"
                          AllowDrop="True" ItemsSource="{Binding ElementName=ScrumBoardItem, Path=DoneItems}" Visibility="Collapsed" Height="200" Background="Transparent" Margin="0,1,0,1" 
                          PreviewTouchDown="OnDragSourcePreviewTouchDown"                                                  
                          s:SurfaceDragDrop.Drop="DoneListBox_OnDropTargetDrop"
                          s:SurfaceDragDrop.DragEnter="OnDropTargetDragEnter"
                          s:SurfaceDragDrop.DragLeave="OnDropTargetDragLeave"
                          s:SurfaceDragDrop.DragCanceled="DoneListBox_DragCanceled"
                          s:SurfaceDragDrop.DragCompleted="DoneListBox_DragCompleted"
                          >
        </s:LibraryStack>

    </Grid>
</UserControl>
